package ch.myDungeons.gameObjects;

import java.io.Serializable;

import ch.myDungeons.game.Map;
import ch.myDungeons.game.Tile;
import ch.myDungeons.io.LanguagePack;

/**
 * A game items which can be found on the floor and picked up by a player or an NPC
 * @author Grii
 *
 */

public abstract class Item implements Serializable{
	private static final long serialVersionUID = -7408559124440142932L;
	
	/** The name of this item */
	public String name = "item";
		
	public Item (String itemName) {
		name = itemName;
	}
	
	/** Returns the tile where the item is landing */
	public Tile getTrowItemTargetTile(int direction, int posX, int posY, Map map) {
		int nextX = map.getPostitionFromDirection(direction, posX, posY)[0];
		int nextY = map.getPostitionFromDirection(direction, posX, posY)[1];
		while (map.checkAccessability(nextX, nextY)) {
			posX = nextX;
			posY = nextY;
			nextX = map.getPostitionFromDirection(direction, posX, posY)[0];
			nextY = map.getPostitionFromDirection(direction, posX, posY)[1];
		}
		if (!map.checkObstacle(nextX, nextY)) {
			posX = nextX;
			posY = nextY;
		}
		Tile targetTile = map.tiles[posX][posY];
		return targetTile;
	}
	
	/** Returns a copy of the item */
	public abstract Item getCopy();

	/** Returns the translated name */
	public String getName(){
		return LanguagePack.get(name);
	}
	
	/** returns name, count, itemtype, .... split at ITEMINFO */
	public String getSave() {
		String result = name;
		return result;
	}
}

